package net.kazed.nextaction.database;

import net.kazed.android.database.Table;
import android.content.ContentValues;
import android.database.Cursor;
import android.provider.BaseColumns;

/**
 * Definition of TaskContext table.
 */
public class TaskContextTable extends Table<TaskContext> {
    
    public static final String TABLE = "task_context";
    public static final String COLUMN_ID = BaseColumns._ID;
    public static final String COLUMN_TASK_ID = "taskId";
    public static final String COLUMN_CONTEXT_ID = "contextId";

    /**
     * Constructor.
     */
    public TaskContextTable() {
        super(TABLE, COLUMN_TASK_ID);
        addColumn(COLUMN_ID);
        addColumn(COLUMN_TASK_ID);
        addColumn(COLUMN_CONTEXT_ID);
    }
    
    /**
     * Extract object from cursor.
     * @param cursor Query cursor.
     * @return Extracted object.
     */
    public TaskContext extract(final Cursor cursor) {
        final long id = getLong(cursor, COLUMN_ID);
        final int taskId = getInteger(cursor, COLUMN_TASK_ID);
        final int contextId = getInteger(cursor, COLUMN_CONTEXT_ID);
        final TaskContext taskContext = new TaskContext(id, taskId, contextId);
        return taskContext;
    }

    /**
     * Insert fragment values into collection.
     * @param fragment Model object.
     * @return Content values.
     */
    public ContentValues getValues(final TaskContext taskContext) {
        final ContentValues values = new ContentValues();
        values.put(COLUMN_TASK_ID, taskContext.getTaskId());
        values.put(COLUMN_CONTEXT_ID, taskContext.getContextId());
        return values;
    }

}
